import { useSelector, useDispatch } from 'react-redux'
import myStore from '@/store/my'
import { ceshi } from '@/request/api'
import { useEffect } from 'react'
function Page() {
    // 获取仓库数据
    const { token } = useSelector((state: { login: { token: string } }) => ({
        token: state.login.token
    }))
    const { num } = useSelector((state: { my: { num: number } }) => ({
        num: state.my.num

    }))

    // 修改仓库数据
    const dispath = useDispatch()
    const changeNum = () => {
        // dispath({type: "字符串（认为是一个记号）", value: 3})
        dispath({ type: "add", value: 1 })
    }
    const changeToken = () => {
        dispath({ type: "setToken", value: 'asdsadwasafnqion--21dsa' })
    }
    const onSetTimeOut = () => {
        dispath(myStore.asyncAtions.asyncAdd as any)
    }
    const sendGet = async () => {
        const ceshidata = await ceshi()
        // ceshi().then(response => {
        //     console.log(response);
        // })
    }
    const init = () => {
        dispath({ type: "setProgressShow", value: true })
        dispath({ type: "setProgressNum", value: 10 })
        setTimeout(() => {
            dispath({ type: "setProgressNum", value: 60 })
            setTimeout(() => {
                dispath({ type: "setProgressShow", value: false })
            }, 1000);
        }, 1000);
    }
    useEffect(() => {
        init()
    }, [])
    return (
        <div>
            <p>这是Page1里面的内容</p>
            <p>获取store数据: token:{token}</p>
            <p>获取store数据: num:{num}</p>
            <button onClick={changeToken}>changeToken</button>
            <button onClick={changeNum}>changeNum</button>
            <hr />
            <p>异步方法</p>
            <button onClick={onSetTimeOut}>onSetTimeOut</button>
            <button onClick={sendGet}>发送请求</button>
        </div>
    )
}

export default Page